package com.gem.day15;

/**
 * 本类用来演示Java创建线程的两种方式之一:
 * 写一个类实现java.lang.Runnable接口,并且重写run()方法
 * 
 * @author easonsy
 * 2020年8月10日 上午9:43:11
 */
public class ThreadDemo2 {
	public static void main(String[] args) {
		//创建线程
		Runnable r = new T2();
		Thread t1 = new Thread(r, "线程一");
		Thread t2 = new Thread(r, "线程二");
		t1.start();
		t2.start();
	}
}

class T2 implements Runnable {
	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			System.out.println(Thread.currentThread().getName() + " : " + i);
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
